package com.itheima.test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/***
 *@title MyJFrame
 *@description <TODO description class purpose>
 *@author 12468
 *@version 1.0.0
 *@create 2024-11-07 23:26
 **/
public class MyJFrame2 extends JFrame implements MouseListener {

    // 创建两个按钮
    JButton jbtn1 = new JButton("按钮1");

    public MyJFrame2() throws HeadlessException {
        //设置界面的宽高
        this.setSize(603, 680);
        //设置界面的标题
        this.setTitle("拼图单机版 v1.0");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //取消默认的居中放置，只有取消了才会按照XY轴的形式添加组件
        this.setLayout(null);

        // 设置两个按钮的位置
        jbtn1.setBounds(0, 0, 100, 100);

        // 给按钮注册鼠标事件
        jbtn1.addMouseListener(this);

        // 将两个按钮添加到界面中
        this.getContentPane().add(jbtn1);

        this.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("移入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("移除");
    }
}
